<template>
  <div>
    <city-header></city-header>
    <city-search :msg='msg'></city-search>
    <city-list :msg='msg' :elementText='elementText'></city-list>
    <city-alphabet :msg='msg' @change='change'></city-alphabet>
  </div>
</template>
<script>
import cityHeader from './components/header'
import citySearch from './components/Search'
import cityList from './components/List.vue'
import cityAlphabet from './components/Alphabet'
import axios from 'axios'
export default {
  name: 'city',
  data () {
    return {
      elementText: '',
      msg: {
        cities: [],
        hotCity: [],
        city: []
      }

    }
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json')
        .then(this.handleCityInfoSucc)
    },
    handleCityInfoSucc (res) {
      const data = res.data
      if (data.ret && data.data) {
        const msg = data.data
        this.msg.city = msg.city
        this.msg.cities = msg.cities
        this.msg.hotCity = msg.hotCities
      }
    },
    change (e) {
      this.elementText = e
    }
  },
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlphabet
  },
  mounted () {
    this.getCityInfo()
  },
  activated () {
    this.scroll && this.scroll.refresh()
  }
}
</script>
<style lang="stylus" scoped>
</style>
